<?php
class ModelLocalisationCountry extends Model {
	public function addCountry($data) {
		$this->db->insert('country', $data);
	}

	public function editCountry($country_id, $data) {
		$this->db->update('country', $data, array('country_id' => $country_id));
	}

	public function deleteCountry($country_id) {
		$this->db->delete('country', array('country_id' => $country_id));
	}

	public function getCountry($country_id) {
		return $this->db->get('country', array('country_id' => $country_id));
	}

	public function getCountries($filter = null) {
		$sql = "SELECT * FROM  @@country";

		if ($filter) {
			$sql .= $filter->sort('name');
			$sql .= $filter->limit();
		}
		
		$query = $this->db->query($sql);

		return $query->rows;
	}

	public function getTotalCountries() {
      	return $this->db->queryOne("SELECT COUNT(*) AS total FROM  @@country");
	}

	public function cache() {
		$country_data = $this->db->queryArray("SELECT country_id, name FROM  @@country WHERE status = 1 ORDER BY name ASC", 'country_id', 'name');
		cache_write('country.php', $country_data);
	}
}
?>